﻿@using DevM.Web.Models.Common.Modals
@using DevM.Development.DataMigration.Dto
@model DevM.Web.Models.DataMigration.EditDataMigrationViewModel<DatabaseDto>
@{
    Layout = null;
}
@await Html.PartialAsync("~/Views/Shared/Modals/_ModalHeader.cshtml", new ModalHeaderViewModel(L("EditConfig")))

<style>
    .add-resource-container .input-group {
        margin-bottom: 0px;
    }

    .resource-name {
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
    }
</style>
<div class="modal-body">
    <form name="DatabaseEditForm" role="form" novalidate class="form-validation">
        <input type="hidden" name="Id" value="@Model.Details.Id" />
        <ul class="nav nav-tabs tab-nav-right" role="tablist">
            <li role="presentation" class="active"><a href="#edit-database-details" data-toggle="tab">@L("DatabaseDetails")</a></li>
            <li role="presentation" class=""><a href="#edit-database-resources" data-toggle="tab">@L("DatabaseResources")</a></li>
        </ul>
        <div class="tab-content">
            <div role="tabpanel" class="tab-pane animated fadeIn active" id="edit-database-details">
                <div class="row clearfix">
                    <div class="col-sm-12">
                        <div class="form-group form-float">
                            <div class="form-line">
                                <textarea type="text" name="Sql" required class="form-control" maxlength="2000">@Model.Details.Sql</textarea>
                                <label class="form-label">@L("Sql")</label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row clearfix">
                    <div class="col-sm-12">
                        <div class="form-group form-float">
                            <div class="form-line">
                                <textarea type="text" name="Description" class="form-control" maxlength="2000">@Model.Details.Description</textarea>
                                <label class="form-label">@L("Description")</label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row clearfix">
                    <div class="col-sm-12">
                        <div class="form-group form-float">
                            <div class="form-line">
                                <textarea type="text" name="Memo" class="form-control" maxlength="2000">@Model.Details.Memo</textarea>
                                <label class="form-label">@L("Memo")</label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--resource-->


            <div role="tabpanel" class="tab-pane animated fadeIn " id="edit-database-resources">

                <script type="text/template" class="add-resource-template">
                    <!--resource template-->
                    <div class="input-group">
                        <div class="input-group">
                            <span class="input-group-btn">
                                <button class="btn btn-xs btn-default btn-select-resource" type="button">@L("SelectResource")</button>
                            </span>
                            <input type="text" class="form-control" readonly placeholder="@L("ResourceName") ...">
                        </div><!-- /input-group -->
                        <input type="file" style="display:none" class="form-control" name="resource">
                        <span class="input-group-btn">
                            <button class="btn btn-xs btn-danger btn-remove-resource" type="button">@L("Remove")</button>
                        </span>
                    </div><!-- /input-group -->
                </script>

                <button class="btn btn-ms btn-primary add-resource" type="button">
                    @L("AddResource")
                </button>
                <br />

                <div class="row clearfix">
                    <div class="col-sm-12">
                        <div class="add-resource-container">
                            <!--模板填充-->
                        </div>
                    </div>
                </div>
                <br />
                @if (Model.Details.Resources != null && Model.Details.Resources.Count > 0)
                {
                    <ul class="list-group">
                        @foreach (var resource in Model.Details.Resources)
                        {
                            <li class="list-group-item">
                                <div class="row clearfix">
                                    <div class="col-sm-12 col-md-8">
                                        <p class="resource-name">
                                            @resource.Resource.Name
                                        </p>
                                    </div>
                                    <div class="col-sm-12 col-md-4">
                                        <button class="btn btn-xs btn-danger btn-remove-resource pull-right" data-databaseresource-id="@resource.Id" data-resource-name="@resource.Resource.Name" type="button">@L("Remove")</button>
                                    </div>
                                </div>
                            </li>
                        }

                    </ul>
                }

            </div>
        </div>
    </form>
</div>

@await Html.PartialAsync("~/Views/Shared/Modals/_ModalFooterWithSaveAndCancel.cshtml")

<script src="~/view-resources/Views/DataMigration/_EditDatabaseModal.js" asp-append-version="true"></script>
